package com.jadows.tdog.template;

import com.jadows.tdog.properties.ChatServerProperties;
import com.jadows.tdog.server.ChatServerOptionHandler;
import com.jadows.tdog.server.option.ChatServerOption;
import com.jadows.tdog.server.option.ServerOption;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author taojiacheng
 */
public abstract class AbstractChatServerHandler implements ChatServerOptionHandler {

    @Autowired
    protected ChatServerProperties properties;


    protected abstract void intercept(ChatServerOption option);

    @Override
    public ChatServerOption getOption() {
        ChatServerOption option = newChatServerOption();
        ServerOption serverOption = new ServerOption(properties.getHost(), properties.getPort());
        option.serverOption(serverOption);
        intercept(option);
        return option;
    }

    protected ChatServerOption newChatServerOption() {
        return new ChatServerOption()
                .parentGroupThread(properties.getParentGroupThread())
                .workerGroupThread(properties.getWorkerGroupThread())
                .publicExecutorThread(properties.getPublicExecutorThread());
    }

}
